home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 6 / CU Amiga Magazine's Super CD-ROM 06 (1996)(EMAP Images)(GB)(Track 1 of 4)[!][issue 1997-01].iso / cucd / prog / gnu-c / include / sys / file.h < prev    next >
C/C++ Source or Header  |  1995-05-17  |  5KB  |  139 lines

  1. /*
  2.  *  This file is part of ixemul.library for the Amiga.
  3.  *  Copyright (C) 1991, 1992  Markus M. Wild
  4.  *
  5.  *  This library is free software; you can redistribute it and/or
  6.  *  modify it under the terms of the GNU Library General Public
  7.  *  License as published by the Free Software Foundation; either
  8.  *  version 2 of the License, or (at your option) any later version.
  9.  *
  10.  *  This library is distributed in the hope that it will be useful,
  11.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  13.  *  Library General Public License for more details.
  14.  *
  15.  *  You should have received a copy of the GNU Library General Public
  16.  *  License along with this library; if not, write to the Free
  17.  *  Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18.  */
  19.  
  20. #ifndef _SYS_FILE_H
  21. #define _SYS_FILE_H
  22.  
  23. #include <sys/types.h>
  24. #include <sys/fcntl.h>
  25. #include <sys/unistd.h>
  26.  
  27. #ifdef _INTERNAL_FILE
  28. #include <sys/stat.h>
  29. #include <libraries/dosextens.h>
  30.  
  31. /* this is the incore representation of a DTYPE_MEM file */
  32. struct mem_file {
  33.   int   mf_offset;
  34.   void *mf_buffer;
  35. };
  36.  
  37. /* this `glue' makes a tty a subtype of a plain file. Ie f->f_fh will work
  38.    for plain files as well as ttys. */
  39. struct tty_glue {
  40.   struct FileHandle *fh;
  41.   struct tty *tty;    /* internal data of tty.c */
  42. };
  43.  
  44. /* this will hold basic information about a file, but contrairy to
  45.  * Unix, it will also hold its name */
  46.  
  47. struct file {
  48.   char *f_name;         /* the name as used with open() */
  49.   int f_stb_dirty,   /* gets == 1, if changes have been made to 'stb' */
  50.       f_type,         /* can be a file or some amiga..devices */
  51.       f_flags,         /* see fcntl.h */
  52.       f_count,         /* open-count, normally 1, higher after dup() */
  53.       (*f_write)(),    /* functions to perform write,read,etc on this fd */
  54.       (*f_read)(),
  55.       (*f_ioctl)(),
  56.       (*f_select)(),
  57.       (*f_close)();
  58.   union {
  59.     struct FileHandle *fh; /* this is a CPTR to the allocated
  60.                 * FileHandle */
  61.     struct mem_file mf;       /* current data for incore files */
  62.     struct socket *so;       /* points to socket when DTYPE_SOCKET */
  63.     struct tmp_pipe *tp;   /* temporary until sockets are here ;-) */
  64.     struct tty_glue tg;
  65.   } f__fh;
  66. #define f_fh  f__fh.fh
  67. #define f_mf  f__fh.mf
  68. #define f_so  f__fh.so
  69. #define f_tp  f__fh.tp
  70. #define f_tty f__fh.tg.tty
  71.   /* WARNING: if you change this struct, take care, that f_sp starts at
  72.    * long (!) alignment in the struct. The file-table will be allocated
  73.    * by AllocMem(), thus by itself it will have DOS-compatible alignment,
  74.    * if you don't follow this, you'll get some nice gurus.. */
  75.   struct StandardPacket f_sp; /* all IO is done thru the Packet-Interface,
  76.                    * not the higher-level DOS-functions */
  77.   char *f_async_buf;
  78.   int   f_async_len;
  79.   struct stat f_stb; /* file-params at open-time, or after changes to fd */
  80.   int    f_sync_flags;    /* for process synchronization */
  81. };
  82.  
  83.  
  84. #define FSFB_LOCKED    (0)
  85. #define FSFF_LOCKED    (1<<0)    /* means the fh is in use */
  86. #define FSFB_WANTLOCK    (1)
  87. #define FSFF_WANTLOCK    (1<<1)    /* means a process is sleeping on fh to get free */
  88.  
  89. #endif /* _INTERNAL_FILE_H */
  90.  
  91.  
  92. #if 0 /* now in <sys/fcntl.h> */
  93. #include <fcntl.h>
  94.  
  95. /*
  96.  * flags - see also fcntl.h
  97.  */
  98. #define    FOPEN        (-1)
  99. #define    FREAD        00001        /* descriptor read/receive'able */
  100. #define    FWRITE        00002        /* descriptor write/send'able */
  101. #define FINDIR        00010        /* result of a dup() call */
  102. #define FEXTOPEN        00020        /* someone else opened this fd for
  103.                      * us, so we shouldn't close it */
  104. #define FTTYRAW        00040        /* did we send a RAW-packet ?? */
  105. #define FUNLINK        00200        /* unlink file after close */
  106.  
  107. /* bits to save after open */
  108. #define    FMASK        (FREAD|FWRITE|FAPPEND|FSYNC|FASYNC|FNBIO|FINDIR)
  109. #define    FCNTLCANT    (FREAD|FWRITE|FINDIR|FEXTOPEN)
  110. #endif
  111.  
  112. #if 0  /* now in sys/fcntl.h sys/unistd.h */
  113. /*
  114.  * Access call.
  115.  */
  116. #define    F_OK        0    /* does file exist */
  117. #define    X_OK        1    /* is it executable by caller */
  118. #define    W_OK        2    /* writable by caller */
  119. #define    R_OK        4    /* readable by caller */
  120.  
  121. /*
  122.  * Lseek call.
  123.  */
  124. #define    L_SET        0    /* absolute offset */
  125. #define    L_INCR        1    /* relative to current offset */
  126. #define    L_XTND        2    /* relative to end of file */
  127. #endif
  128.  
  129. #define DTYPE_FILE    1    /* 'file' is really a file */
  130. #define DTYPE_PIPE    2    /* it's an incore pipe */
  131. #define DTYPE_MEM    3    /* a RDONLY file completely buffered in memory */
  132. #define DTYPE_TASK_FILE    4    /* is a 'file', but used by a task, not a process !*/
  133. #define DTYPE_SOCKET    5    /* socket (inet.library interface) */
  134. #define DTYPE_USOCKET    6    /* socket (own socket code) */
  135. #define DTYPE_TTY    7    /* amigados file, with special access functions */
  136. /* more to follow.. */
  137.  
  138. #endif /* _SYS_FILE_H */
  139.